﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1.wtyczki
{
    public partial class CutForm : Form
    {
        int bmWidth;
        int bmHeight;
        public CutForm(Bitmap bm)
        {
            bmHeight = bm.Height;
            bmWidth = bm.Width;
            InitializeComponent();
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = (Image)bm;
            
        }
        public List<int> TheValue
        {
            
            get { List<int> lst=new List<int>();
            double xScale = (double)bmWidth / (double)pictureBox1.Width;
                double yScale = (double)bmHeight/(double)pictureBox1.Height ;
                 lst.Add( (int)(Int32.Parse( cutXinit.Text)*xScale));
                lst.Add( (int)(Int32.Parse( cutYinit.Text)*yScale));
                lst.Add( (int)(Int32.Parse( cutXsize.Text)*xScale));
                lst.Add( (int)(Int32.Parse( cutYsize.Text)*yScale));

                return lst;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (cutXinit.Text == null)
            {
                cutXinit.Text="0";
            }
            if (cutYinit.Text ==null)
            {
                cutYinit.Text="0";
            }
            if (cutXsize.Text ==null)
            {
                cutXsize.Text="0";
            }
                
            if (cutYsize.Text ==null)
            {
                cutYsize.Text="0";
            } 
            Close();
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            cutXinit.Text = e.Location.X.ToString();
            cutYinit.Text = e.Location.Y.ToString();
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
   
            cutXsize.Text = (e.X - Int32.Parse(cutXinit.Text)).ToString();
            cutYsize.Text = (e.Y - Int32.Parse(cutYinit.Text)).ToString();
            
            
            
        }   
    }
}
